import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:mobile_app.core/core/presentation/helpers/screen_util_mixin.dart';
import 'package:mobile_app.core/core/presentation/theme/theme.dart';
import 'package:mobile_app.core/core/presentation/widgets/app_button.dart';

class ScaledNavigationBarTextButton extends StatelessWidget with ScreenUtilMixin {
  const ScaledNavigationBarTextButton({
    required this.text,
    required this.onPressed,
    this.isDefault = false,
    this.navigationButtonAutoSizeGroup,
    super.key,
  });

  final String text;
  final bool isDefault;
  final VoidCallback onPressed;
  final NavigationBarTextButtonAutoSizeGroup? navigationButtonAutoSizeGroup;

  @override
  Widget build(BuildContext context) {
    late TextStyle textStyle;

    if (isDefault) {
      textStyle = CoreTheme.of(context).textTheme.navigationBarBoldButton;
    } else {
      textStyle = CoreTheme.of(context).textTheme.navigationBarButton;
    }

    return SizedBox(
      height: double.infinity,
      child: AppButton(
        padding: EdgeInsets.symmetric(
          horizontal: 16 * logWidthScaleFactor,
        ),
        onPressed: onPressed,
        child: AutoSizeText(
          text,
          style: textStyle,
          stepGranularity: 0.1,
          maxLines: 1,
          group: navigationButtonAutoSizeGroup?._autoSizeGroup,
        ),
      ),
    );
  }
}

class NavigationBarTextButtonAutoSizeGroup {
  NavigationBarTextButtonAutoSizeGroup() : _autoSizeGroup = AutoSizeGroup();
  final AutoSizeGroup _autoSizeGroup;
}
